<template>
    <div class="layout-padding-auto">
    <el-table :data="state.dataList" v-loading="state.loading" border style="width: 100%;height: 100%;"
              :cell-style="tableStyle.cellStyle" :header-cell-style="tableStyle.headerCellStyle"
              @selection-change="selectionChangHandle"
              @sort-change="sortChangeHandle">
        <el-table-column prop="materialCode"  :label="$t('so.materialcode')" show-overflow-tooltip  width="150"/>
        <el-table-column prop="asnCode" :label="$t('podetail.asnCode')" />
        <el-table-column prop="sourcePo" :label="$t('srmAsnD.matchingOrderNumber')" show-overflow-tooltip />
        <el-table-column prop="sourcePoLine" :label="$t('podetail.poLine')" show-overflow-tooltip  width="100"/>
        <el-table-column prop="sourcePoQty" :label="$t('SrmPoHeaderGroup.orderTotalNum')" show-overflow-tooltip width="150">
            <template #default="scope">
                <!--根据不同的状态选择不同的颜色的tag-->
                <el-tag size="large" type='primary' >
                    {{ scope.row.sourcePoQty }}
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="assignQty" :label="$t('srmAsnD.quantityAllocatedThisTime')" show-overflow-tooltip width="150">
            <template #default="scope">
                <!--根据不同的状态选择不同的颜色的tag-->
                <el-tag size="large" type='success' >
                    {{ scope.row.assignQty }}
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="ManyAllotQty" :label="$t('podetail.manyQty')" show-overflow-tooltip width="150">
            <template #default="scope">
                <!--根据不同的状态选择不同的颜色的tag-->
                <el-tag size="large" type='info' >
                    {{ scope.row.ManyAllotQty }}
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="creationTime" :label="$t('srmAsnD.creationTime')" show-overflow-tooltip width="200"/>
        <el-table-column prop="createUserNo" :label="$t('srmAsnD.createUserNo')" show-overflow-tooltip width="180"/>
    </el-table>
    <pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination"/>
</div>
  <!-- 编辑、新增  -->
    <form-dialog ref="formDialogRef" @refresh="getDataList(false)"/>
</template>

<script setup lang="ts" name="systemSrmPodetail">
import {BasicTableProps, useTable} from "/@/hooks/table";
import {allocationDetails} from "/@/api/platform/srm/srmAsnH";


// 定义变量内容
const formDialogRef = ref()
// 多选变量
const selectObjs = ref([]) as any
const multiple = ref(true)
// 搜索变量
const queryRef = ref()

// 父级点击的行
const parentClickRow = {}

const state: BasicTableProps = reactive<BasicTableProps>({
    queryForm: {},
    pageList: allocationDetails
})

// 清空搜索条件
const resetQuery = () => {
    // 清空搜索条件
    queryRef.value?.resetFields()
    getDataList(false)
}

onMounted (()=>{
    query(props.rowList)
})

//  table hook
const {
    getDataList,
    currentChangeHandle,
    sizeChangeHandle,
    sortChangeHandle,
    tableStyle
} = useTable(state)

const props = defineProps({
    rowList: {
        type: Object,
    },
})

// 通过id进行子表的查询
const query = (row: Object) => {
    // 赋值查询参数
    state.queryForm.asnCode = row.asnCode
    // 保存选中的行数据
    Object.assign(parentClickRow, row)
    // 刷新子表数据
    getDataList()
}

// 多选事件
const selectionChangHandle = (objs: { id: string }[]) => {
    selectObjs.value = objs.map(({id}) => id);
    multiple.value = !objs.length;
};

// 暴露变量
defineExpose({
    resetQuery,
    query
});


</script>